import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'dva';
import { InputItem, Button, Toast } from 'antd-mobile';
import { routerRedux } from 'dva/router';
import { createForm } from 'rc-form';
import styles from './index.less';

class index extends Component {
  constructor(props) {
    super(props);
  }
  doLogin = () => {
    const { dispatch } = this.props;
    const { validateFields } = this.props.form;
    validateFields((err, value) => {
      if (err) {
        const { userName, passWord } = err;
        if (userName) {
          Toast.info('用户名输入格式不正确...');
          return;
        }
        if (passWord) {
          Toast.info('密码输入格式不正确...');
          return;
        }
        return
      }
      dispatch({type: 'login/login',payload:value})
    });
  };
  doReset = () => {};
  render() {
    const { getFieldProps } = this.props.form;
    return (
      <div className={styles.panel}>
        <div className={styles.loginP}>
          <div className={styles.item}>
            <InputItem
              {...getFieldProps('userName', { rules: [{ required: true }] })}
              placeholder="请输入用户名..."
            >
              用户名
            </InputItem>
          </div>
          <div className={styles.item}>
            <InputItem
              {...getFieldProps('passWord', { rules: [{ required: true }] })}
              placeholder="请输入密码..."
              type="password"
            >
              密码
            </InputItem>
          </div>
          <Button className={styles.btn} onClick={() => this.doLogin()}>
            登录
          </Button>
          {/* <Button className={styles.btn} onClick={() => this.doReset()}>重置</Button> */}
          <div />
        </div>
      </div>
    );
  }
}
export default connect(login => ({ login }))(createForm()(index));
